﻿//创建时间: 2010-12-14
//创建作者: 李晓忠
//功能说明: 广告设置
//最后修改: 2010-12-14

using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using System.Collections;

namespace TRPOP.CMS.Web.Admin
{
    public partial class advertisement_setting : BaseAdmin
    {
        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_strPagePermissionExtraKey = "Plugin_Advertisement";
        }
        #endregion

        #region 页面变量
        protected string m_Title = "编辑插件信息";
        protected string m_strRefer = "advertisement_list.aspx";
        #endregion

        #region 页面事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strRoot = txtAdvertisementRoot.Text.Trim();
            string strUpLoadRoot = txtAdvertisementUpLoadRootPSN.Text.Trim();
            if (strRoot == "")
            {
                strRoot = "/";
            }
            else if (strRoot.IndexOf("/") != 0)
            {
                strRoot = "/" + strRoot;
            }

            if (strUpLoadRoot == "")
            {
                strUpLoadRoot = "/";
            }
            else if (strUpLoadRoot.IndexOf("{PSN") == 0)
            {
                //strRoot = "/" + strRoot;
            }
            else if (strUpLoadRoot.IndexOf("/") != 0)
            {
                strUpLoadRoot = "/" + strUpLoadRoot;
            }

            AdvConfigInfo oAdvConfigInfo = SYSConfig.AdvertisementConfigInfo;

            oAdvConfigInfo.Enable = rbtAdvertisementEnable.SelectedValue.ToBool();
            oAdvConfigInfo.URL_Dynamic = txtAdvertisementDynamicAccessUrl.Text.Trim();
            oAdvConfigInfo.FilesRoot = strRoot;
            oAdvConfigInfo.DelPastFile = rbtAdvertisementDel.SelectedValue.ToBool();
            oAdvConfigInfo.Mode = rbtAdvertisementTypeDefault.SelectedValue.ToInt();
            oAdvConfigInfo.ResourceRoot = strUpLoadRoot;
            oAdvConfigInfo.URL_Skip = txtAdvertisementSkipURL.Text.Trim();
            oAdvConfigInfo.URL_Skip = txtAdvertisementUpLoadRootUrl.Text.Trim();

            base.SaveLog(Plugin.LogKeys.OperObject.PluginOper, Plugin.LogKeys.OperResult.EditSubmit, "Advertisement");

            SYSConfig.AdvertisementConfigInfo = oAdvConfigInfo;

            SubmitAlertAndThisNewLocation(true, m_strRefer);

        }

        #endregion

        #region 页面方法

        public void LoadBase()
        {
            AdvConfigInfo oAdvConfigInfo = SYSConfig.AdvertisementConfigInfo;

            rbtAdvertisementEnable.SelectedValue = oAdvConfigInfo.Enable.ToString().ToLower();
            txtAdvertisementDynamicAccessUrl.Text = oAdvConfigInfo.URL_Dynamic;
            txtAdvertisementRoot.Text = oAdvConfigInfo.FilesRoot;
            rbtAdvertisementDel.SelectedValue = oAdvConfigInfo.DelPastFile.ToString().Trim();
            rbtAdvertisementTypeDefault.SelectedValue = oAdvConfigInfo.Mode.ToString().Trim();
            txtAdvertisementUpLoadRootPSN.Text = oAdvConfigInfo.ResourceRoot;
            txtAdvertisementUpLoadRootUrl.Text = oAdvConfigInfo.URL_Skip;
            txtAdvertisementSkipURL.Text = oAdvConfigInfo.URL_Skip;

        }
        public void CheckConfig(ArrayList oVarArray)
        {
            if (oVarArray == null)
            {
                Alert("请通过正确的途径进入本页面");
                base.ExecuteJs("window.location.href='" + m_strRefer + "'");
                return;
            }
        }
        #endregion
    }
}
